Skip to content

Fix pr-labeler for fork PRs (pull_request_target)#3581

Merged
SusanneWindfeldPedersen merged 1 commit into
mainfrom
revert/pr-labeler-autogen-warning
May 28, 2026
Merged

Fix pr-labeler for fork PRs (pull_request_target)#3581
SusanneWindfeldPedersen merged 1 commit into
mainfrom
revert/pr-labeler-autogen-warning

Conversation

@SusanneWindfeldPedersen

@SusanneWindfeldPedersen SusanneWindfeldPedersen commented May 28, 2026

Copy link
Copy Markdown
Contributor

Problem

The \label-pr\ workflow fails on PRs from forks (#3579) with:

\
Resource not accessible by integration (403)
\\

This happens because \pull_request\ events only get a read-only \GITHUB_TOKEN\ for fork PRs, regardless of declared permissions.

Fix

  • Switch trigger from \pull_request\ to \pull_request_target\ (runs in base repo context → write access)
  • Explicitly checkout the PR head SHA (since \pull_request_target\ defaults to the base branch)
  • Fetch base branch and diff using explicit refs

Security note

\pull_request_target\ is safe here because we only read file content from the PR (no execution of PR-supplied code). The workflow script is always from the base branch.

@learn-build-service-prod

Copy link
Copy Markdown
Contributor

Learn Build status updates of commit 93115ba:

✅ Validation status: passed

File Status Preview URL Details
.github/workflows/pr-labeler.yml ✅Succeeded n/a (file deleted or renamed)

For more details, please refer to the build report.

The workflow failed on fork PRs (#3579) because pull_request events
only get a read-only GITHUB_TOKEN for forks. Switch to
pull_request_target which runs in the base repo context with write
permissions.

Key changes:
- Trigger: pull_request_target instead of pull_request
- Checkout the PR head SHA explicitly (pull_request_target defaults
  to base)
- Fetch base branch and diff against explicit refs

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@SusanneWindfeldPedersen SusanneWindfeldPedersen force-pushed the revert/pr-labeler-autogen-warning branch from 93115ba to 202c7c0 Compare May 28, 2026 11:02
@SusanneWindfeldPedersen SusanneWindfeldPedersen changed the title Revert: Remove pr-labeler workflow (failing on PRs) Fix pr-labeler for fork PRs (pull_request_target) May 28, 2026
@learn-build-service-prod

Copy link
Copy Markdown
Contributor

Learn Build status updates of commit 202c7c0:

✅ Validation status: passed

File Status Preview URL Details
.github/workflows/pr-labeler.yml ✅Succeeded

For more details, please refer to the build report.

@SusanneWindfeldPedersen SusanneWindfeldPedersen merged commit 99d0320 into main May 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant